let sqlserver = require('mssql');
let dbConfigSource = {
    server: '172.30.199.163\\dev',
    database: 'MR_FS_DB',
    user: 'sa',
    password: 'Docimax@123',
    port: 1433
};
let con = undefined
async function getConnection() {
    if (con == undefined) {
        con = await sqlserver.connect(dbConfigSource);
    }
    return con;
}
async function getData(strsql, pool) {
    let data = [];
    try {
        if (pool == undefined)
            pool = await getConnection()
        let rs = await pool.request().query(strsql);
        //console.log(rs);
        for (let i = 0; i < rs.recordset.length; i++) {
            let element = rs.recordset[i]
            //let d = await getExtInfo(element, pool)
            data.push(element);
            console.log(i / rs.recordset.length)
        }
        return data
    } catch (error) {
        console.log(error);
    } finally {
        //await pool.close();
    }

}
module.exports.test = async () => {
    try {

        let pool = await getConnection()
        //var pool = new sqlserver.ConnectionPool(dbConfigSource);
        //await pool.connect();
        //let request = pool.request();
        //request.multiple = true;
        //let result = await request.query('select ICD_Name,ICD_Code from Dic_ICD_Diagnosis ');
        let result = await getData('select ICD_Name,ICD_Code from Dic_ICD_Diagnosis ', pool)
        //console.log('query finished');
        console.log(result);

    } catch (error) {
        console.log(error);
    } finally {
        //await doRelease(pool);
        await sqlserver.close();
    }
}